package com.znz.service;

import com.znz.domain.Part;
import com.znz.domain.Project;
import com.znz.domain.Torder;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: duyuxin
 * Date: 15-6-1
 * Time: 下午6:17
 * To change this template use File | Settings | File Templates.
 */
@Service
public class CommonService {

    //TODO 根据部位查询项目
    /**
     * @param partId 部位ID
     * @return
     */
    public List<Project> getProjectListByPart(Long partId) {
        List<Project> projectList=new ArrayList<Project>();
        List<Object> params=new ArrayList<Object>();
        StringBuilder  where=new StringBuilder();
        if(null!=partId){
            where.append(" and o.part.id=? ");
            params.add(partId);
        }
        try {
            projectList= Torder.getProjectAllByPartId(where.toString(), params);
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return   projectList;
    }
    //TODO 获取所有的部位
    /**
     * @return   JSONArray
     */
    public List<Part> getPartAll(){
        List<Part> partList=Part.findAllParts();
        if(null!=partList){
            return  partList;
        }
        return null;
    };
}
